# Matthew Pore
# WSU id: f366n723
# Program pgm56.py
#
# Description
# --------------------
# This program caclulates the numeric value of an
# inputted name. "a" is 1, "b" is 2, "c" is 3 etc., up
# to "z" being 26.
#
# Psuedo Code
# --------------------
# Will get a name from user input. Only letters a-z and A-Z will be
# accepted. Any other input will tell the user that only letters are
# accepted. Lowercase and uppercase letters have the same value.
# For example: C and c are both equal to 3. Spaces and periods are
# both acceptable in names but they will not change the numeric
# value. The input will be saved to
# a variable then the program will run a for loop that and use
# ord() to assign a value to each letter and then add them together
# to get the numerical value. Final result will be printed out to the user.

# This input is used to help with handling input we don't want to accept
import re

def main():

    numericalValue = 0

    # Gets the name from the user. Also handles when something other
    # then a character is entered    
    inputName = input ("Enter  a name to find out it's numerical value: ")

    if (not re.match("[a-z]", inputName)) or (not re.match("[A-Z]", inputName)):
        print ("Error: Only letters are allowed. Please try again.")

    # Converts the name to lower case so we get the same
    # numeric value regardless of case. Helps especially with
    # names like McLovin McDonalds
    lowerCaseName = inputName.lower()

    # Takes the inputted name, assigns appropriate value
    # to each letter and adds the values together to get the
    # total numerical value
    for ch in lowerCaseName:
        # Minus 96 here so it takes the ASCII value and changes to
        # the range 1-26 which is what we need
        charValue = ord(ch) - 96

        # Ignores the space and period character when adding up numeric values 
        if charValue == -64 or charValue == -50:
            charValue = 0

        numericalValue += charValue

    # Prints out the numerical value of the inputted name
    print ("The numeric value of", inputName, "is:", numericalValue)

main()
